//
//  AudioTableViewCell.m
//  DolphinMusic
//
//  Created by dllo on 15/3/27.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "AudioTableViewCell.h"

@implementation AudioTableViewCell

- (void)dealloc
{
    [_audio release];
    [_coverImageView release];
    [_titleLabel release];
    [_authorLabel release];
    [_playCountImageView release];
    [_playCountLabel release];
    [_timeImageView release];
    [_timeLabel release];
    [_downLoadButton release];
    [_playButton release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.coverImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.coverImageView];
        [_coverImageView release];
        
        self.playCountImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.playCountImageView];
        [_playCountImageView release];
        
        self.timeImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.timeImageView];
        [_timeImageView release];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        [_titleLabel release];
        
        self.authorLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.authorLabel];
        [_authorLabel release];
        
        self.playCountLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.playCountLabel];
        [_playCountLabel release];

        self.timeLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.timeLabel];
        [_timeLabel release];

//        self.downLoadButton = [UIButton buttonWithType:UIButtonTypeSystem];
//        [self.contentView addSubview:self.downLoadButton];
//        
//        self.playButton = [UIButton buttonWithType:UIButtonTypeSystem];
//        [self.contentView addSubview:self.playButton];
        
        
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat width = self.contentView.frame.size.width;
    CGFloat height = self.contentView.frame.size.height;
    
    self.coverImageView.frame = CGRectMake(10, 20, height - 40, height - 40);
    
    self.coverImageView.layer.masksToBounds = YES;
    self.coverImageView.layer.cornerRadius = 35;
    [self.coverImageView setImageWithURL:[NSURL URLWithString:[self.audio.coverLarge stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
    
    self.titleLabel.frame = CGRectMake(10 + height - 40 + 10, 20, width - (10 + height - 40 + 10) - 20, 40);
    self.titleLabel.text = self.audio.title;
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    self.titleLabel.numberOfLines = 2;
//    [self.titleLabel sizeToFit];
    
    self.authorLabel.frame = CGRectMake(self.titleLabel.frame.origin.x + 10, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height + 5, self.titleLabel.frame.size.width, 20);
    self.authorLabel.font = [UIFont systemFontOfSize:15];
    self.authorLabel.text = [NSString stringWithFormat:@"by %@", self.audio.nickname];
    
    self.playCountImageView.frame = CGRectMake(self.authorLabel.frame.origin.x, self.authorLabel.frame.origin.y + self.authorLabel.frame.size.height + 5, 20, 20);
    self.playCountImageView.alpha = 0.8;
    self.playCountImageView.contentMode = UIViewContentModeCenter;
    self.playCountImageView.image = [UIImage imageNamed:@"playNumber.png"];
    
    self.playCountLabel.frame = CGRectMake(self.playCountImageView.frame.origin.x + 20, self.playCountImageView.frame.origin.y, 65, 20);
    self.playCountLabel.font = [UIFont systemFontOfSize:12];
    self.playCountLabel.text = self.audio.playCount;
    
    self.timeImageView.frame = CGRectMake(self.playCountLabel.frame.origin.x + self.playCountLabel.frame.size.width, self.playCountLabel.frame.origin.y, 20, 20);
    self.timeImageView.image = [UIImage imageNamed:@"clock.png"];
    self.timeImageView.contentMode = UIViewContentModeCenter;
    
    self.timeLabel.frame = CGRectMake(self.timeImageView.frame.origin.x + 20, self.timeImageView.frame.origin.y, 65, 20);
    self.timeLabel.font = [UIFont systemFontOfSize:12];
    self.timeLabel.text = self.audio.time;
//    
//    self.downLoadButton.frame = CGRectMake(self.timeLabel.frame.origin.x + self.timeLabel.frame.size.width, self.timeLabel.frame.origin.y + 2, 16, 16);
//    self.downLoadButton.contentMode = UIViewContentModeCenter;
//    [self.downLoadButton setBackgroundImage:[UIImage imageNamed:@"download.png"] forState:UIControlStateNormal];
    
    
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
